package com.jf.identity.config;

import java.io.Serializable;
import java.util.Optional;

/**
 * 数据源 信息
 *
 * @author FCG
 */
public class DataBaseBean implements Serializable {
    private static final long serialVersionUID = -6654436258674268584L;
    private static final String DEFAULT_DRIVER_NAME = "com.mysql.jdbc.Driver";
    private final static String dbConnUrlStr
            = "?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false" +
            "&allowMultiQueries=true&useSSL=true";
    private String providerName= DEFAULT_DRIVER_NAME;
    private String host;
    private String port;
    private String user;
    private String pwd;
    private String dbName;

    public String getConnectionUrl() {
        host = Optional.ofNullable(host).orElseGet(String::new);
        port = Optional.ofNullable(port).orElseGet(String::new);
        dbName = Optional.ofNullable(dbName).orElseGet(String::new);
        return "jdbc:mysql://" + host + ":" + port +"/"+ dbName + dbConnUrlStr;
    }

    public String getProviderName() {
        return providerName;
    }

    public void setProviderName(String providerName) {
        this.providerName = providerName;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    @Override
    public String toString() {
        return "DataBaseBean{" +
                "providerName='" + providerName + '\'' +
                ", host='" + host + '\'' +
                ", port='" + port + '\'' +
                ", user='" + user + '\'' +
                ", pwd='" + pwd + '\'' +
                ", dbName='" + dbName + '\'' +
                '}';
    }
}

